/*


  审核状态标识：正常：1；不正常：0

  filter_in_com		写入状态公司名称
  filter_in_info	写入状态非公司名称
  filter_out_com	公司名称输出
  filter_out_info	数据输出
  filter_jk_com		监控 公司名称;
  filter_jk_info	监控 非公司名称

*/
package cn.yj.core.kwfilter;


import java.util.HashSet;
import java.util.Set;

public class WordFilter {
    public KeyWordFilter kwf = KeyWordFilter.getInstance();

    public String filter_in_com(String content) {
        return kwf.filter_in(content, "1", "0");
    }

    public String filter_in_info(String content) {
        return kwf.filter_in(content, "0", "0");
    }

    /**
     * 标记出敏感词
     *
     * @param content
     */
    public String filter_jk_com(String content) {
        return kwf.filter_jk(content, "1", "0", "<font color=#ff0000>", "</font>", "<font color=#ff0000>", "</font>");
    }


    public String filter_jk(
            String content, String sta, String mgcstyle1, String mgcstyle2, String wfcstyle1, String wfcstyle2) {
        return kwf.filter_jk(content, sta, "0", mgcstyle1, mgcstyle2, wfcstyle1, wfcstyle2);
    }

    /**
     * 过滤掉敏感词，直接删除敏感脆
     *
     * @param content
     */
    public String filter_search(String content) {
        return kwf.filter_search(content);
    }

    public Set<String> filter_search_out_word(String content) {
        String filterSearch = filter_jk_com(content);
        String start = "<fontcolor=#ff0000>";
        String end = "</font>";
        Set<String> words = new HashSet<String>();
        filter_word(words, filterSearch, start, end);
        return words;
    }

    private void filter_word(Set<String> words, String content, String start, String end) {
        content=content.replaceAll(" ","");
        int i = content.indexOf(start);
        int i2 = content.indexOf(end);
        if (i < 0 || i2 < 0) {
            return;
        }
        String word = content.substring(i+start.length(), i2);
        content = content.replace(content.substring(i, i2 + end.length()), "");
        words.add(word);
        filter_word(words, content, start, end);
    }


    /*
     * 重新读取词库文件
     */
    public boolean reload() {
        return kwf.reload();
    }

}
